package com.cn.kabalifeuser.ui.integral.fragment;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.integral.bean.BannerActBean;
import com.cn.kabalifeuser.ui.integral.bean.ShoppingMalListBean;
import com.cn.kabalifeuser.ui.service.bean.BannerListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/10.
 * function:
 */
public class ShoppingMallPresenter extends BasePresenter<ShoppingMallView> {
    public void onBannerData(String token, int type) {
        OkGo.<BannerListBean>post(Api.API_INDEX_BANNER)
                .headers("token", token)
                .params("type", type)
                .execute(new CacheCallBack<BannerListBean>() {
                    @Override
                    public void onSuccess(Response<BannerListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("banner：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onBannerSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 活动baner
     *
     * @param token
     */
    public void onBannerActData(String token) {
        OkGo.<BannerActBean>get(Api.API_GOODS_BANNER)
                .headers("token", token)
                .execute(new CacheCallBack<BannerActBean>() {
                    @Override
                    public void onSuccess(Response<BannerActBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("banner活动：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onBannerActSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onShoppingMallData(String token, String category_id, String reco, String title, int page, int limit) {
        OkGo.<ShoppingMalListBean>get(Api.API_INDEX_GOODS_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("reco", reco)
                .params("category_id", category_id)
                .params("title", title)
                .execute(new CacheCallBack<ShoppingMalListBean>() {
                    @Override
                    public void onSuccess(Response<ShoppingMalListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onShoppingMalListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onShoppingMallData(String token, String title, int category_id, int page, int limit) {
        OkGo.<ShoppingMalListBean>get(Api.API_INDEX_GOODS_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("title", title)
                .params("category_id", category_id)
                .execute(new CacheCallBack<ShoppingMalListBean>() {
                    @Override
                    public void onSuccess(Response<ShoppingMalListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onShoppingMalListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
